<template>
  <div>
    <el-row>
      <el-col :span="24">
         <div class="header">
          <label for="assistant" style="font-size:20px;font-weight: 600; line-height: 40px;margin-right:5px">未提交辅导员信息</label>
        </div>
        <el-col :span="3"> 
          <div style="margin-left:50px">
           <el-select v-if="userInfo.username ==='jiaoyuting'|| userInfo.username ==='admin'" v-model="form.sch_name" placeholder="选择或输入学校" filterable  clearable>
             <el-option
               v-for="item in schools"
               :key="item.value"
               :label="item.sch_name"
               :value="item.sch_name">
             </el-option>
           </el-select> 
         </div>  
        </el-col>
        <el-col :span="3"> 
          <div class="header" style="width:180px;margin-left:22%;" v-if="userInfo.username ==='jiaoyuting'|| userInfo.username ==='admin'">
           <el-input v-model="form.idcard" auto-complete="off" placeholder="输入身份证号" filterable></el-input>
          </div>
        </el-col>
        <el-col :span="2"> 
          <div class="header" style="width:30px;margin-left:44%;" v-if="userInfo.username ==='jiaoyuting'|| userInfo.username ==='admin'">
           <el-button type="primary" icon="el-icon-search" @click="getTableData();getSearchData()">搜索</el-button>
         </div>
        </el-col> 
      </el-col>
    </el-row>
    <el-row style="border-top: 1px solid black; margin-top: 15px">
      <el-table
       @selection-change="handleSelectionChange"
       :data="tableData"
       v-loading="loading"
       style="width: 100%;margin-bottom: 10px;"
       :row-style="showSex"
       >
        <el-table-column
         type="selection"
         width="55">
         </el-table-column>
         <el-table-column
         prop="id"
         label="id"
         width="90">
       </el-table-column>
       <el-table-column
         label="姓名"
         prop="name"
         width="160">
       </el-table-column>
       <el-table-column
         label="性别"
         prop="sex"
         width="130">
       </el-table-column>
       <el-table-column
         label="工作单位"
         prop="sch"
         width="190">
       </el-table-column>
       <el-table-column
         label="工作部门"
         prop="level_1"
         width="190">
       </el-table-column>
       
       <el-table-column
         
         prop="page"
         width="108">
       </el-table-column>
       <el-table-column
         label='身份证号'
         prop="idnumber"
         width="170">
       </el-table-column>
       <el-table-column
         width="160">
       </el-table-column>
       <el-table-column
         width="160">
       </el-table-column>
       <el-table-column   width="140">
       </el-table-column>
        <el-table-column
         width="130">
         <template slot-scope="scope"> 
            <!-- name的值是配置路由文件对某界面的命名name，接受值this.$router.params.id  -->
            <router-link :to="{name: 'personmsg',
                             params: {id: scope.row.id,
                                      last: '1',
                                      searchData: searchData
                                     }
                             }" 
                             class="btn-link  el-icon-edit">
           <!-- 查看详情 -->
           </router-link>
         </template>
       </el-table-column>
      </el-table>
    </el-row>
    <el-pagination
     v-show="allPage>1"
     layout="prev, pager, next"
     :page-count="allPage"
     :current-page="nowPage"
     @current-change="goPage" 
     class="pull-right" background>
   </el-pagination>
  </div>
 </template>
 
 <script>
 import http from '../../../../src/assets/js/http'
 export default {
   data () {
     return {
       // tableData: [],
       allPage: 1,
       nowPage: 1,
       tableData: [],
       option1: [{
         value: '1',
         label: '男'
       },{
         value: '2',
         label: '女'
       }],
       options: [{
           value: 1,
           label:'本、专科学生工作队伍工作管理',
           children: [{
             value: 1,
             label: '本、专科生专职辅导员'
           },{
             value: 2,
             label: '学工管理干部'
           },{
             value: 3,
             label: '本、专科生兼职辅导员'
           }]
         },{
           value: 2,
           label:'研究生学生工作队伍工作管理',
           children: [{
             value: 1,
             label: '研究生专职辅导员'
           },{
             value: 2,
             label: '研工管理干部'
           },{
             value: 3,
             label: '研究生兼职辅导员'
           }]
         },{
           value: 3,
           label: '心理健康专职教师管理',
           children: [{
             value: 1,
             label: '心理健康专职教师'
           }]
         }],
       form: {
         sch:'',
         sch_address: '',
         sch_name: '',
         name: '',
         sex: '',
         idnumber:'',
         idcard:''
       },
       schAddress: [],
       dialogFormVisible: false,
       multipleSelection: [],
       selectId: [],
       userInfo: Lockr.get('userInfo'),
       loading: true,
       schools: Lockr.get('schInfo'),
       searchData: {}
     }
   },
   methods: {
     init() {
       this.getTableData()
     },
     
     // 保存搜索数据
     getSearchData() {
       this.searchData = { 
         // sch: this.userInfo.sch,
         sex: this.form.sex,
         name: this.form.name,
         sch_address: this.form.sch_address,
         sch_name: this.form.sch_name,
         idnumber:this.form.idcard
       }
      
     },
     // 获取条件查询的所在学校地
     getSchaddress() {
       this.apiPost('admin/Train/TeacherYear').then((res) =>{
         // console.log(res);
           this.handelResponse(res,(data)=>{
             console.log(res.data)
             this.schAddress = data.sch_address
             
           })
       })
     },
     //获取数据填充表格
     getTableData() {
       if(this.$route.params.searchData === undefined) {
         console.log(this.userInfo.sch);
         var data = {
           page:this.nowPage,
           sch: this.userInfo.sch,
           sex: this.form.sex,
           name: this.form.name,
           idnumber: this.form.idcard,
           sch_name: this.form.sch_name,
           level_1: this.userInfo.level_1
         }
       } else {
         var data = {
           page:this.nowPage,
           sch: this.userInfo.sch,
           sex: this.$route.params.searchData.sex,
           name: this.$route.params.searchData.name,
           idnumber: this.$route.params.searchData.idnumber,
           sch_name: this.$route.params.searchData.sch_name,
           level_1: this.userInfo.level_1   //未定
         }
         this.form = this.$route.params.searchData
         
       }
       console.log(this.form);
       // console.log(this.userInfo.sch)
       // let data ={
       //   page:this.nowPage,
       //   sch:this.userInfo.sch,
       //   level_1:this.userInfo.level_1
       // }
       console.log(data)
       this.apiPost('admin/Train/TeacherUnSubmit',data).then((res) => {
         this.handelResponse(res, (data) => {
           console.log(res.data)
           this.tableData = []
           data.data.forEach((element) => {
             
             if(element.sex === 1) {
               element.sex = "男"
             } else if (element.sex === 2) {
               element.sex = "女"
             }
             if(element.level_1===1){
               element.level_1=this.options[0].label;
             }else if(element.level_1===2){
               element.level_1=this.options[1].label;
             }else{
               element.level_1=this.options[2].label;
             }
             // var sch_name=element.sch_name;
                 this.tableData.push({
                 id: element.id,
                 level_1:element.level_1,
                 name: element.name,
                 page:element.page,
                 idnumber:element.idnumber,
                 // sch: this.userInfo.realname,
                 // sch:element.sch,
                 sch: Lockr.get('schInfo')['sch_id_'+element.sch].sch_name,
                 // sch: this.schools['sch_id_'+element.sch].sch_name,
                 // sch_name:element.sch_name,
                 sex: element.sex,
                
             }) 
           })
           this.allPage = data.last_page
           _g.closeGlobalLoading()
           this.loading = false
         })
       })
     },
     handleSizeChange(size) {
       this.pagesize = size
       console.log(this.pagesize)
     },
     // 复选框信息
     handleSelectionChange(val) {
       console.log(val)
       this.multipleSelection = val
     }, 
     // 审核通过
 
     // 添加行样式
     showSex() {
       // return { 'background-color': '#f0f9eb'}
     },
     // 根据页面渲染数据
     goPage(num) {
       this.nowPage = num
       console.log(num)
       this.getTableData()
     },
     // 添加辅导员信息
     addAssist() {
       console.log(2)
       // this.$router.go(-1)
       this.$router.push({
         name: 'impList'
       })
     }  
   },
   created() {
     _g.closeGlobalLoading()
     this.init()
     // this.getSchaddress()
   },
   mounted() {
     // window.addEventListener('keyup', (e) => {
     //   if(e.keyCode === 13) {
     //     this.getTableData()
     //     this.dialogFormVisible=false
     //   }
     // })
   },
   computed: {
   },
   components: {
   },
   mixins: [http]
 }
 
 </script>
 <style scoped>
   .header {
      float: left;
      margin-left: 10px;
   }
   .button {
     margin-left: 15px;
     margin-top: -5px;
   }
   .searchInfo {
     background-color: #2980D9;
   }
   .el-table th, .el-table tr {
     height: 57px
   }
 </style>
 